fetch("http://chst.vip:1234/api/getindexmenu")
    .then(body => body.json())
    .then(res => {
        let resultarr = res.result
        let imgsrc = ["indexIconImages/1.png", "indexIconImages/2.png", "indexIconImages/3.png", "indexIconImages/4.png", "indexIconImages/5.png", "indexIconImages/6.png", "indexIconImages/7.png", "indexIconImages/8.png", "indexIconImages/9.png", "indexIconImages/10.png", "indexIconImages/11.png", "indexIconImages/12.png"]
        arr = resultarr.map((item, index) => {
            return {
                ...item, img: imgsrc[index]
            }
        })
        let str = ""
        arr.forEach(item => {
            str += `
        <li><img src="${item.img}"><p>${item.name}</p></li>
        `
        });
        $("#nav ul").html(str)
        //点击nav跳转-------------------------------------------------------
        $("#nav ul li:eq(0)").click(function(){
            window.location.href="pages/bjss.html"
        })//比价搜索
        $("#nav ul li:eq(1)").click(function(){
            window.location.href="pages/sqk_list.html"
        })//省钱控
        $("#nav ul li:eq(2)").click(function(){
            window.location.href="pages/gnzk_list.html"
        })//国内折扣
        $("#nav ul li:eq(3)").click(function(){
            window.location.href="pages/bcj.html"
        })//白菜价
        $("#nav ul li:eq(4)").click(function(){
            window.location.href="pages/sqk_list.html"
        })//海淘折扣
        $("#nav ul li:eq(5)").click(function(){
            window.location.href="pages/yhq.html"
        })//优惠券
        $("#nav ul li:eq(6)").click(function(){
            window.location.href="pages/bjss.html"
        })//查历史价
        $("#nav ul li:eq(8)").click(function(){
            window.location.href="pages/cdp.html"
        })//凑单品
        $("#nav ul li:eq(9)").click(function(){
            window.location.href="pages/bjss.html"
        })//口碑排行
        $("#nav ul li:eq(10)").click(function(){
            window.location.href="pages/shopnav.html"
        })//商城导航
        $("#nav ul li:eq(11)").click(function(){
            window.location.href="pages/ppdq.html"
        })//品牌大全
    })
//请求商品数据
fetch("http://chst.vip:1234/api/getmoneyctrl")
    .then(body => body.json())
    .then(res => {
        let resultarr = res.result
        let str = ""
        resultarr.forEach(item => {
            str += `
        <li productId=${item.productId}>
        ${item.productImgSm}
        <p class="jieshao">${item.productName}<span class="pinkage">${item.productPinkage}</span></p>
        <p class="biaoqian">${item.productFrom}|${item.productTime}<span class="pinlun" id="x"><span class="iconfont icon-pinglun"></span>${item.productComCount}</span></p>
        </li>
        `
        })
        $(".lis").html(str)
        //注册点击事件，跳转页面并传参productId
        $("#main .lis").on("click","li img",function(e){
            let _this = e.target
            let clickid = $(_this).parent().attr("productId")
            //跳转页面，动态拼接id
            window.location.href=`pages/sqk_detail.html?productId=${clickid}`
        })
        //获取更多抽屉效果
        let li = $("#nav ul").find("li:eq(7)")
            li.prop('isExpand', true).click(function (e) {
                e.preventDefault()
                let isExpand = $(this).prop('isExpand')
                if (isExpand) {
                    $(this).prop('isExpand', false).nextAll().slideUp(300)
                } else {
                    $(this).prop('isExpand', true).nextAll().slideDown(300)
                }
            })
        })
//点击返回顶部
let scrolltop = document.documentElement.scrollTop
$("#foot ul .li3").click(function () {
    $("html,body").animate({ scrollTop: 0 }, 500)
})